import configparser
import os

class ReadConfig:
    """定义一个读取配置文件的类"""

    def __init__(self, section, filepath = None):
        self.section = section
        root_dir = os.getcwd()
        if filepath:
            configpath = os.path.join(root_dir, filepath)
        else:
            configpath = os.path.join(root_dir, "config.ini")
        self.cf = configparser.ConfigParser()
        self.cf.read(configpath)

    def get_db(self, param):
        value = self.cf.get(self.section, param)
        return value